package app.util.image.action
{
	import app.util.*;
	
	import flash.display.*;
	import flash.geom.*;
	
	public class FlipAction extends AbstractAction
	{
		private var isVertical:Boolean;
		
		public function FlipAction(v:Boolean)
		{
			this.isVertical = v;
		}
		
		public override function getDescription():String
		{
			return "Flip " + (this.isVertical ? "Vertically" : "Horinzontally");
		}
		
		public override function getActionedBitmapData():BitmapData
		{
			var oldBmp:BitmapData = Mediator.getCurrentBitmapData();			
			var m:Matrix = new Matrix();
			if(this.isVertical)
			{
				m.scale(1, -1);
				m.translate(0, oldBmp.height);
			}
			else
			{
				m.scale(-1, 1);
				m.translate(oldBmp.width, 0);
			}
			 
			var rotated:BitmapData = new BitmapData(
			  		oldBmp.width, oldBmp.height, true, 0x0);
			rotated.draw(oldBmp, m);
			
			return rotated;
		}
	}
}